package com.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @author 爱Java的小于
 */
public interface UserDao extends BaseMapper<User> {
    /**
     * 批量插入用户信息 - 使用 @Insert 注解方式
     * @param userList 用户列表
     * @return 插入的行数
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("<script>" +
            "INSERT INTO user (user_name, user_sex, user_age, user_address, user_phone, user_political) " +
            "VALUES " +
            "<foreach collection='userList' item='user' separator=','>" +
            "(#{user.userName}, #{user.userSex}, #{user.userAge}, #{user.userAddress}, #{user.userPhone}, #{user.userPolitical})" +
            "</foreach>" +
            "</script>")
    int inserts(@Param("userList") List<User> userList);
}
